package taxicall.entities;

import java.io.Serializable;
import java.net.InetAddress;

public class Taxi implements Serializable {

	private static final long serialVersionUID = 6056570121529011689L;

	private static int lastTaxiId = 0;
	private int id;
	private InetAddress ip;
	
	private int availableSeats;
	private TaxiLocation location;
	
	// use to create a taxi without id which should be confirmed by the server
	public static Taxi createWithoutId(InetAddress ip, TaxiLocation location){
		Taxi t = new Taxi(ip);
		t.id = 0;
		t.location = location;
		return t;
	}
	
	public Taxi(){
		this.id = newId();
		this.availableSeats = 4;
	}

	public Taxi(InetAddress ip) {
		this.id = newId();
		this.availableSeats = 4;
		this.ip = ip;
	}
	
	private int newId() {
		return ++lastTaxiId;
	}

	public TaxiLocation getLocation() {
		return location;
	}

	public void setLocation(TaxiLocation location) {
		this.location = location;
	}
	
	public int getId() {
		return this.id;
	}

	public int getAvailableSeats() {
		return availableSeats;
	}

	public void setAvailableSeats(int availableSeats) {
		if(availableSeats < 0 || availableSeats > 4)
			throw new IllegalArgumentException("availableSeats cannot be:" + availableSeats);
		
		this.availableSeats = availableSeats;
	}
	
	public InetAddress getIp() {
		return this.ip;
	}
	
	public void setIp(InetAddress ip) {
		this.ip = ip;
	}
}
